package net.tv90.bfmccore.util;

import net.tv90.bfmccore.util.vector.Vector3i;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class GeneralUtil {

    public static <T> List<T> getRandomSublist(List<T> list, int n) {
        if(list.isEmpty()) {
            return new ArrayList<>();
        }
        Random r = ThreadLocalRandom.current();
        int count = Math.min(list.size(), n);
        List<T> temp = new ArrayList<>(list);
        List<T> result = new ArrayList<>(n);
        for (int i = 0; i < count; i++) {
            int t = r.nextInt(temp.size());
            result.add(temp.get(t));
            temp.remove(t);
        }
        return result;
    }


    public static <T> T getRandomElement(List<T> list) {
        if(list.isEmpty()) {
            return null;
        }
        return list.get(ThreadLocalRandom.current().nextInt(list.size()));
    }
}
